package com.glory.wxmemsicpda.utils

import android.util.Log
import com.glory.wxmemsicpda.base.Constant.MES_REQUST_URL
import com.glory.wxmemsicpda.base.Constant.REQUEST_URL
import com.glory.wxmemsicpda.bean.net.BaseRequestBean
import com.glory.wxmemsicpda.bean.net.HeaderBean
import com.glory.wxmemsicpda.bean.net.RequestBean
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.lzy.okgo.OkGo
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_SimpleEntityCallBack
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils
import java.util.*

object NetUtils {
    fun <T> requestPosNet(
        tag: Any?,
        method: String,
        messageName: String,
        jsonString: JsonObject,
        callBack: FreeUI_SimpleEntityCallBack<T>?
    ) {
        val format = RequestBean()
        format.body = jsonString
        format.header = HeaderBean(messageName)
        val message = BaseRequestBean()
        message.request = format
        val map: MutableMap<String, String> = HashMap()
        map["requestMessage"] = Gson().toJson(message)
        map["senderId"] = "EAP2CPCSender"
        Log.e("json", map.toString())
        FreeApi_LogUtils.saveErrorMessages(map.toString(),"请求JSON")
        FreeApi_LogUtils.saveErrorMessages(REQUEST_URL + "/api/" + method,"请求地址")
        OkGo.post<T>(REQUEST_URL + "/api/" + method)
            .tag(tag)
            .params(map,*booleanArrayOf(true))
            .execute(callBack)
    }
    fun <T> requestMesPosNet(
        tag: Any?,
        method: String,
        messageName: String,
        jsonString: JsonObject,
        callBack: FreeUI_SimpleEntityCallBack<T>?
    ) {
        val format = RequestBean()
        format.body = jsonString
        format.header = HeaderBean(messageName)
        val message = BaseRequestBean()
        message.request = format
        val map: MutableMap<String, String> = HashMap()
        map["requestMessage"] = Gson().toJson(message)
        map["senderId"] = "EAP2CPCSender"
        Log.e("json", map.toString())
        FreeApi_LogUtils.saveErrorMessages(map.toString(),"请求JSON")
        FreeApi_LogUtils.saveErrorMessages(MES_REQUST_URL + "/api/" + method,"请求地址")
        OkGo.post<T>(MES_REQUST_URL + "/api/" + method)
            .tag(tag)
            .params(map,*booleanArrayOf(true))
            .execute(callBack)
    }


}